package com.hsav.kcxb.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.activity.SingerWorkActivity;
import com.kcbsdk.MyTools.AIconTypeList;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhao on 2017/2/12.
 */

public class SingerListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private final Context mContext;
    private final LayoutInflater mInflater;
    private final List<AIconTypeList> data;

    public SingerListAdapter(Context context, ArrayList<AIconTypeList> data){
        this.data = data;
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = mInflater.inflate(R.layout.item_singer_view,parent,false);
        return new SingerViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        AIconTypeList item = data.get(position);
        SingerViewHolder holder1 = (SingerViewHolder) holder;
        holder1.mHeadImg.setImageURI(Uri.fromFile(new File(item.IconFile)));
        holder1.mNameTx.setText(item.TypeName);
        holder1.viewDummy.setTag(position);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    private class SingerViewHolder extends RecyclerView.ViewHolder{

        public ImageView mHeadImg;
        public TextView mNameTx;
        public View viewDummy;

        public SingerViewHolder(View itemView) {
            super(itemView);
            viewDummy = itemView;
            viewDummy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = (int)v.getTag();
                    AIconTypeList item = data.get(position);
                    SingerWorkActivity.startWithFilterSingerName(mContext, item.TypeName);
                }
            });
            mHeadImg = (ImageView)itemView.findViewById(R.id.img_singer_face);
            mNameTx = (TextView)itemView.findViewById(R.id.text_song_name);
        }
    }
}
